package org.wannatrak.android.helper;

import android.content.Context;
import android.util.Log;

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 * @Author: Maksim Tulupov maxtulupov@gmail.com
 * @Date: $Date: 2011-06-14 13:32:03 +0000 (Tue, 14 Jun 2011) $ 3:09:03 PM
 * @version: $Revision: 2 $
 * @id: $Id: IOHelper.java 2 2011-06-14 13:32:03Z maxtulupov@gmail.com $
 */
public class IOHelper {

    public static final String SEPARATOR = "\n";

    public static String readResourceAsString(Context context, int resourceId) {
        InputStream inputStream = context.getResources().openRawResource(resourceId);
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder sb = new StringBuilder();
        String str;
        try {
            while ((str = br.readLine()) != null) {
                sb.append(str).append(SEPARATOR);
            }
        } catch (IOException e) {
            Log.e(IOHelper.class.getSimpleName(), "error loading resource by id = " + resourceId, e);
            throw new RuntimeException(e);
        }
        return sb.toString();
    }
}
